package com.movie.demo.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.movie.demo.mapper.OrderMapper;
import com.movie.demo.pojo.Order;
import com.movie.demo.pojo.vo.OrderInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Objects;

@Service
public class OrderService extends ServiceImpl<OrderMapper, Order> implements com.movie.demo.service.OrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public List<OrderInfo> Selectorder() {
        List<OrderInfo> resultlist = orderMapper.getAllInfo();
        return resultlist;
    }

    @Override
    public boolean deleteOrder(Integer oid) {
        boolean flag = orderMapper.deleteOrder(oid);
        return flag;
    }

    @Override
    public List<OrderInfo> searchOrder(int id) {
        List<OrderInfo> orderInfos = orderMapper.getUserorder(id);
        return orderInfos;
    }

    @Override
    public boolean updateOrder(OrderInfo orderInfo) {
        boolean result = orderMapper.updateOrder(orderInfo.getOid(), orderInfo.getCname(),
                orderInfo.getChinese_name(), orderInfo.getType(), orderInfo.getLength(),orderInfo.getTime(),
                orderInfo.getPrice(), orderInfo.getR_name(), orderInfo.getSeat(), orderInfo.getAccount(),
                orderInfo.getUserphone(), orderInfo.getState(),orderInfo.getCreate_time());
        return result;
    }

    @Override
    public boolean addOrder(Order order) {
        order.setCreate_time(new Date());
        return this.insert(order);
    }

    @Override
    public boolean UpdateOrderState(int oid, int state){
        Order order = this.selectById(oid);
        if (Objects.isNull(order) || order == null)return false;
        order.setState(state);
        boolean result=this.updateById(order);
        return result;
    }
}
